#pragma once
#include "Sort.hpp"
#include "TimeRecordUtil.h"

void GenerateTestData(std::vector<std::string>& sort_data, int size)
{
	std::srand(time(nullptr));

	for (int i = 0; i < size; ++i)
	{
		int str_size = (std::rand() % 15) + 1;
		std::string rand_str = "";
		for (int j = 0; j < str_size; ++j)
			rand_str.push_back(std::rand() % ('z' - 'a') + 'a');

		sort_data.push_back(rand_str);
	}
}
void GenerateTestData(std::vector<int>& sort_data, int size)
{
	std::srand(time(nullptr));
	sort_data.push_back(rand() % (size * 50));
	for (int i = 1; i < size; ++i)
	{
		int thesame_last_percent = 50 + rand() % 25;
		bool is_thesame_last = (rand() % 100) + 1 > thesame_last_percent;
		if (is_thesame_last)
			sort_data.push_back(sort_data.back());
		else
			sort_data.push_back(rand() % (size * 50));
	}
}


void RunSortDemo()
{
	/**
	 *	InsertSort test:100 size:10000  time:372
	 *
	 *  MedianSort test:100 size:100000 average_time:121 <select kth to pick pivot,recursive,decay to insert sort>
	 *  MedianSort test:100 size:100000 average_time:252 <select kth to pick pivot,none recursive,decay to insert sort>
	 *
	 *  QuickSort test:100 size:100000 arverage_time:54  <median-of-3 to pick pivot,recursive,decay to insert sort>
	 *  QuickSort test:100 size:100000 arverage_time:53  <random to pick pivot,recursive,decay to insert sort>
	 *  QuickSort test:100 size:100000 arverage_time:226 <median-of-3 to pick pivot,none recursive,decay to insert sort>
	 *
	 *  HeapSort  test:100 size:100000 arerage_time:107
	 */

	std::vector<int> sort_data;
	TimeRecordUtil& time_record = TimeRecordUtil::It();
	int sort_tch = time_record.NewRecord();

	const int test_size = 100;
	const int data_size = 10000;
	const bool print_data = false;

	for (int i = 0; i < test_size; ++i)
	{
		GenerateTestData(sort_data, data_size);

		if (print_data)
			PrintData(sort_data.data(), sort_data.size());

		time_record.MakeRecord(sort_tch);
		InsertSort(sort_data.data(), sort_data.size());
		time_record.MakeRecord(sort_tch);
		time_record.Collapse(sort_tch);

		if (print_data)
			PrintData(sort_data.data(), sort_data.size());

		CheckInOrder(sort_data.data(), sort_data.size());
		sort_data.clear();
	}

	std::cout << "cost time average:" << time_record.GetAverage(sort_tch) << std::endl;
}